package com.soda.dao.impl;

import java.sql.SQLException;
import java.util.List;

import com.soda.bean.Survey;
import com.soda.dao.BaseDao;
import com.soda.dao.SurveyDao;

public class SurveyDaoImpl extends BaseDao implements SurveyDao {

	 
	public  Survey  show(int surType) {
			try {
				getConnection();
				String sql="select * from survey where sur_type=?";
				pt=conn.prepareStatement(sql);
				pt.setInt(1, surType);
				 
				res=pt.executeQuery();
				if(res.next()){
					Survey sv=new Survey(res.getInt(1), res.getString(2), res.getString(3), res.getInt(4));
				return sv;
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				close();
			}
			
		return null;
	}
 
	public int update(int types,String title,String neirong) {
	 
		try {
			getConnection();
			String sql="update survey set sur_title=?,sur_content=? where sur_type=?";
			pt=conn.prepareStatement(sql);
			pt.setString(1, title);
			pt.setString(2, neirong);
			pt.setInt(3, types);
			
		return pt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			close();
		}
		return 0;
	}
 
	public int update2(int types, String neirong) {
		 

		try {
			getConnection();
			String sql="update survey set sur_content=? where sur_type=?";
			pt=conn.prepareStatement(sql);
		
			pt.setString(1, neirong);
			pt.setInt(2, types);
			
		return pt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			close();
		}
		return 0;
	}

}
